/**
 给访问路径前面在添加层级
 比如原来访问的地址是localhost:3000/index 
 添加层级后变成localhost:3000/levy/index 
 或者 localhost:3000/levy/afaart/index 中间可以任意添加层级
*/

const Koa = require ('koa');
const Router = require ('koa-router');

const app = new Koa();
const router = new Router({
    prefix : '/levy' //添加  /levy  层级
});

router
    .get('/index', async ctx => {
        ctx.body = 'levy下的index子路由';
    })
    .get('/todo', async ctx => {
        ctx.body = 'levy下的todo子路由';
    });

app
    .use(router.routes())
    .use(router.allowedMethods);

app.listen(3000, () => {
    console.log('[Server] is running at port 3000.');
});
